package com.lq.ecoldchain.ui.withdraw

import android.arch.lifecycle.MutableLiveData
import com.lq.ecoldchain.base.viewmodel.BaseViewModel
import com.lq.ecoldchain.internet.BaseObserver
import com.lq.ecoldchain.util.MD5
import com.lq.ecoldchain.util.toast

/*
*2019/1/10 0010  17:15
*function by lq
*/
class WithdrawViewModel:BaseViewModel(){
    val bankName by lazy { MutableLiveData<String>() }
    val bankId by lazy { MutableLiveData<String>() }
    val bankNo by lazy { MutableLiveData<String>() }
    val payPassword by lazy { MutableLiveData<String>() }
    val money by lazy { MutableLiveData<String>() }
    val realmoney by lazy { MutableLiveData<String>() }
    val num by lazy { MutableLiveData<String>() }

    init {
        bankName.value = "暂未选择银行卡"
    }

    fun addAll(){
        num.value = realmoney.value
    }

    fun commit(){
        if(bankId.value.isNullOrEmpty() ||num.value.isNullOrEmpty()||payPassword.value.isNullOrEmpty()){
            toast { "请填写完整信息" }
        }else{
            BaseNetCore.ApiServiceImpl.submitWithdraw(MD5.encode(payPassword.value!!),num.value!!,bankId.value!!).compose(RxTransformer.switchSchedulers()).subscribe(object:BaseObserver<String>(){
                override fun onSuccess(t: String?) {
                    toast { "提现成功" }
                }

                override fun onFail(code: String) {}
            })
        }
    }
}